package com.jianguo.web.controller.companion;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jianguo.common.annotation.Log;
import com.jianguo.common.core.controller.BaseController;
import com.jianguo.common.core.domain.AjaxResult;
import com.jianguo.common.enums.BusinessType;
import com.jianguo.companion.domain.PzCompanion;
import com.jianguo.companion.service.IPzCompanionService;
import com.jianguo.common.utils.poi.ExcelUtil;
import com.jianguo.common.core.page.TableDataInfo;

/**
 * 陪诊员用户Controller
 *
 * @author hxq
 * @date 2024-03-15
 */
@RestController
@RequestMapping("/companion/companion")
public class PzCompanionController extends BaseController
{
    @Autowired
    private IPzCompanionService pzCompanionService;

    /**
     * 查询陪诊员用户列表
     */
    @PreAuthorize("@ss.hasPermi('companion:companion:list')")
    @GetMapping("/list")
    public TableDataInfo list(PzCompanion pzCompanion)
    {
        startPage();
        List<PzCompanion> list = pzCompanionService.selectPzCompanionList(pzCompanion);
        return getDataTable(list);
    }

    /**
     * 导出陪诊员用户列表
     */
    @PreAuthorize("@ss.hasPermi('companion:companion:export')")
    @Log(title = "陪诊员用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PzCompanion pzCompanion)
    {
        List<PzCompanion> list = pzCompanionService.selectPzCompanionList(pzCompanion);
        ExcelUtil<PzCompanion> util = new ExcelUtil<PzCompanion>(PzCompanion.class);
        util.exportExcel(response, list, "陪诊员用户数据");
    }

    /**
     * 获取陪诊员用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('companion:companion:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(pzCompanionService.getById(id));
    }

    /**
     * 新增陪诊员用户
     */
    @PreAuthorize("@ss.hasPermi('companion:companion:add')")
    @Log(title = "陪诊员用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PzCompanion pzCompanion) {
        return toAjax(pzCompanionService.save(pzCompanion));
    }

    /**
     * 修改陪诊员用户
     */
    @PreAuthorize("@ss.hasPermi('companion:companion:edit')")
    @Log(title = "陪诊员用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PzCompanion pzCompanion) {
        return toAjax(pzCompanionService.updateById(pzCompanion));
    }

    /**
     * 删除陪诊员用户
     */
    @PreAuthorize("@ss.hasPermi('companion:companion:remove')")
    @Log(title = "陪诊员用户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(pzCompanionService.removeByIds(Arrays.asList(ids)));
    }
}
